﻿using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class CompanyUserInformationRepository :
        BaseRepository
            <CompanyUserInformation, SmatimeDataset.CompanyUserInfomationDataTable, CompanyUserInfomationTableAdapter>
    {
        /// <summary>
        ///     get user name by company id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<CompanyUserInformation> GetUserNameByCompanyId(long id)
        {
            using (var adapter = new CompanyUserInfomationTableAdapter())
            {
                using (var table = adapter.GetUserNameByCompanyId(id))
                {
                    var list = new List<CompanyUserInformation>();
                    foreach (DataRow row in table.Rows)
                    {
                        var usersOfCompany = new CompanyUserInformation();
                        usersOfCompany.FromDataRow(row);
                        list.Add(usersOfCompany);
                    }
                    return list;
                }
            }
        }
        public CompanyUserInformation GetByEmail(string email)
        {
            using (var adapter = new CompanyUserInfomationTableAdapter())
            {
                using (SmatimeDataset.CompanyUserInfomationDataTable table = adapter.GetDataByEmail(email))
                {
                    if (table.Count == 0)
                    {
                        return null;
                    }
                    return (CompanyUserInformation)(new CompanyUserInformation().FromDataRow(table.Rows[0]));
                }
            }
        }
    }
}